From 8d68c698752c120deab043ff371378e6954a9a29 Mon Sep 17 00:00:00 2001 From: "iap10@freefall.cl.cam.ac.uk" Date: Thu, 1 Dec 2005 02:43:04 +0100 Subject: [PATCH] Add a new /proc/xen file called 'capabilities'. Currently, when read in dom0 it will return 'control_d', and be empty when read in a guest. This provides a convenient way to allow the root user to detect whether they're running in a guest or dom0, and e.g. gate whether to start xend. In future, when we add more fine grained capabilities we will add other details into this file. Signed-off-by: ian@xensource.com --- .../drivers/xen/privcmd/privcmd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c index dff9343c5f..107f3e8bef 100644 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c @@ -33,6 +33,7 @@ #include static struct proc_dir_entry *privcmd_intf; +static struct proc_dir_entry *capabilities_intf; static int privcmd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long data) @@ -234,6 +235,18 @@ static struct file_operations privcmd_file_ops = { .mmap = privcmd_mmap, }; +static int capabilities_read(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int len = 0; + *page = 0; + + if (xen_start_info->flags & SIF_INITDOMAIN) + len = sprintf( page, "control_d\n" ); + + *eof = 1; + return len; +} static int __init privcmd_init(void) { @@ -241,6 +254,10 @@ static int __init privcmd_init(void) if (privcmd_intf != NULL) privcmd_intf->proc_fops = &privcmd_file_ops; + capabilities_intf = create_xen_proc_entry("capabilities", 0400 ); + if (capabilities_intf != NULL) + capabilities_intf->read_proc = capabilities_read; + return 0; } -- 2.30.2